// TOWN SCRIPT
//    Town 1: Fort Orchid.

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int choice;

body;

beginstate INIT_STATE;

set_crime_tolerance(1);

set_name(6,"Luke"); //M
set_level(6,15);
set_name(7,"Bill"); //M
set_name(8,"Bill"); //M
set_name(10,"Sandra"); //F
set_name(11,"Rosaline"); //F
set_name(12,"Meditating Soldier"); //M
set_name(13,"Grant"); //M
set_name(14,"Alexandra"); //F
set_name(16,"Father Maher"); //M
set_name(17,"Commander Hollie"); //F
set_name(20,"Cross"); //M
set_name(22,"Captain Morley");

set_character_pose(15,14); //Make the sleeping archer lie

if((get_flag(2,5) == 1) && (get_flag(50,2) == 0) && (get_flag(50,3) == 0)) {
	message_dialog("You arrive back in Fort Orchid. Up ahead you can see Captain Morley. He must have got back before you.","");
	activate_hidden_group(4);
}

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;

beginstate 10; //Smithy Greeting
	if(get_flag(1,0) == 0) {
		message_dialog("As you enter this large smithy, you are taken aback by the amazing amount of heat in here. Despite the door being thrown wide open, and several paneless windows set into the walls, the temperature is formidable.","Through the hazy air, you see two blacksmiths working hard at huge anvils. From this angle, they both look identical. Must be a trick of the light...");
		set_flag(1,0,1);
	} 
break;

beginstate 11; //Bookshelves in Alchemy
	message_dialog("These shelves contain all manner of books and papers, scribbled notes and diagrams, all on the subject of creating potions. However, most of it seems either too difficult for you, or else totally useless.","It would take weeks to sort through them to find something helpful. Alas, you don't have that amount of time to spare.");
break;

beginstate 12; //Altar. Once prayed at gives a one-time blessing (restoration)
	reset_dialog();
	add_dialog_str(0,"The altar dazzles brilliantly as you approach it. The closer you draw near, the more you want to get down on bended knee and pray. Do you kneel and pay your respects to the Gods?",0);
	add_dialog_choice(0,"Yes");
	add_dialog_choice(1,"No");
	choice = (run_dialog(1));
	if((choice == 1) && (get_flag(1,1) == 0)) {
		message_dialog("You kneel down and offer a prayer to whatever Divine Beings are listening. As you do, the altar glows, heals your wounds, and removes your fatigue. Finally, you finish your prayer, and stand up refreshed.","");
		revive_party();
		set_flag(1,1,1);
		end();
	}
	if((choice == 1) && (get_flag(1,1) == 1)) {
		message_dialog("You kneel down and offer a prayer to whatever Divine Beings are listening. As you do, the altar glows slightly. This time, though, it is less bright than before. You must have drained it's reserves of energy.","You should try coming back tomorrow - it may have recharged by then.");
	}
	if(choice == 2) {
		end();
	}
break;

beginstate 13; //Locked Lockers in Fletchery
	message_dialog("These two cabinets are locked tight. Beneath the handle is a small silver keyhole, and several runes are printed on the hinges. You're not going to be able to open them unless you find the key.","");
	block_entry(1);
break;

beginstate 14; //Temple Greeting
	if(get_flag(1,2) == 0) {
		message_dialog("As you enter this small, yet well-built temple, a wave of positive energy washes over you, making you instantly feel at ease, and for a few moments at least, you can forget your mission and the murderer on the loose.","");
		set_flag(1,2,1);
	}
break;

beginstate 15; //Dummy in Fletchery
	message_dialog("This training dummy has several long gashes in it, and more than a few broken arrows sticking out from the packed straw inside. Unfortunately, it's completely useless to you.","");
break;

beginstate 16; //Fletchery Shelves
	message_dialog("These bookshelves contain various books about archery, from serious textbooks on crafting bows to works of fiction like _Robin Hood_. Despite the wide range of material, there is nothing here that you can use.","");
break;

beginstate 17; //Fletchery Greeting
	if(get_flag(1,3) == 0) {
		message_dialog("The first thing that hits you about this large wooden building as you enter is the obscene amount of projectiles lying around. This must be Fort Orchid's fletchery.","The second thing that strikes you is the amount of wood shavings around the place. You can already feel your nose tickling...");
		set_flag(1,3,1);
	}
break;

beginstate 18; //Dog
	message_dialog("This little dog is napping peacefully beside his master. When you get closer, he opens an eye slightly, looks you over, and then closes it again. He doesn't seem inclined to give you anymore attention.","");
break;

beginstate 19; //Lockers in Suppply Depot
	message_dialog("These two cabinets are locked tight. The latches are held firmly shut by two huge padlocks. You're not going to be able to open them unless you find the key.","");
	block_entry(1);
break;

beginstate 20; //Greeting message
	if(get_flag(1,9) == 0) {
		reset_dialog();
		add_dialog_str(0,"It's a clear and warm morning, despite the air being slightly sticky. You have your first proper look around Fort Orchid. It is a modest place, yet somehow appealing because of that. It feels homey, and welcoming, a rare thing for an Empire fort.",0);
		add_dialog_str(1,"Looking around, you see that the ground is dotted with various mushrooms and plants. They must flourish in the humid environment.",0);
		add_dialog_str(2,"There don't seem to be many people around, perhaps the fort hasn't yet received its full compliment of men yet. You look around for the Commander to get your mission. They will probably be in the barracks...",0);
		run_dialog(1);
		set_flag(1,9,1);
	}
break;

beginstate 21; //Leaving scenario
	if(get_flag(2,5) == 0) { //If they haven't done anything about shade
		reset_dialog();
		add_dialog_str(0,"You return to the docks at Fort Orchid. There is a small boat here, ready to take you back to the mainland, if that is what you desire.",0);
		add_dialog_str(1,"However, you haven't completed your mission, and the murderer is still at large. If you go back now, you will not get paid for any of the work you have done so far. Still, the choice is yours.",0);
		add_dialog_str(2,"Do you wish to leave the island, and the scenario?",0);
		add_dialog_choice(0,"Yes, I want out.");
		add_dialog_choice(1,"No, I want to stay.");
		choice = run_dialog(1);
		if(choice == 1) {
			set_state_continue(23);
		} else block_entry(1); 
	}
	if(get_flag(2,5) == 1) { //If they have finished quest, either by killing or whatever...
		reset_dialog();
		add_dialog_str(0,"You return to the docks at Fort Orchid. There is a small boat here, ready to take you back to the mainland, if that is what you desire.",0);
		add_dialog_str(1,"You have completed your mission, and uncovered who the murderer was. And you made sure that this can never happen again here. All in all, you did a very good job. Now it's time to go home, and get paid.",0);
		add_dialog_str(2,"Do you want to leave the island, and the scenario?",0);
		add_dialog_choice(0,"Yes, I want out.");
		add_dialog_choice(1,"No, I want to stay.");
		choice = run_dialog(1);
		if(choice == 1) {
			set_state_continue(22);
		} else block_entry(1); 
	}
break;

beginstate 22; //Rewards and such, on leaving
	if(get_flag(2,1) == 1) {
		set_state_continue(25);
	}
	if(get_flag(2,2) == 1) {
		set_state_continue(26);
	}
break;			
				
beginstate 23; //Leaving. Lost
	message_dialog("You board the boat, and cast a final glance at Fort Orchid. Then, after a few moments waiting, you set off for the mainland. Whilst you didn't bring the murderer to justice, you did manage to avoid falling victim to him.","That's not a bad outcome, all things considered. THE END.");
	end_scenario(0);
break;

beginstate 24; //Storeroom Greeting
	if(get_flag(1,10) == 0) {
		message_dialog("You enter a large dusty room, filled with lockers and tables heaving with miscellany. This must be the supply depot for goods entering the island, and where the troops are outfitted.","You look around, and spot a shrewish-looking man sat at a desk, scribbling away. That must be the quartermaster.");
		set_flag(1,10,1);
	}
break;

beginstate 25; //Won, killed shade.
	change_coins(1000);
	reset_dialog();
	add_dialog_str(0,"You board the boat, and give Fort Orchid one final glance. You managed to avenge the deaths of those that lost their lives here, and prevent anything like this happening again. Finally, after a short wait, the boat sets off.",0);
	add_dialog_str(1,"When you get back to the mainland, you tell the entire story to the Empire Liaison who gave you the job. He gets you to repeat the story to him, and as you tell him you slew the shade, as per your orders, he nods.",0);
	add_dialog_str(2,"_Good. Such a vile creature shouldn't have been allowed to leave, no matter what sob story it told. You did well, and will be rewarded accordingly._",0);
	add_dialog_str(3,"He goes into a chest at his side, and pulls out a pouch of coins, which he gives to you. _Here, these are a token of the Empire's gratitude. Now, I'm a busy man. I must get on. Good luck in your future travels!_",0);
	add_dialog_str(4,"You leave the office with heads held high. Not only did you destroy a monster, you're also 1,000 gold pieces richer. All in a day's work...",0);
	run_dialog(1);
	end_scenario(1);
break;

beginstate 26; //Won, freed shade
	change_coins(350);
	reset_dialog();
	add_dialog_str(0,"You board the boat, and give Fort Orchid one final glance. You managed to put right a terrible accident, and prevent anything like this happening again. Finally, after a short wait, the boat sets off.",0);
	add_dialog_str(1,"When you get back to the mainland, you tell the entire story to the Empire Liaison who gave you the job. He gets you to repeat the story to him, and as you tell him you freed the shade, against your orders, he frowns.",0);
	add_dialog_str(2,"_I'm sure you were put under a lot of pressure to help the, erm, _poor_ creature, but you disobeyed an order to do so. Still, you did well, it's a shame that your reward will have to be altered according to your conduct.._",0);
	add_dialog_str(3,"He goes into a chest at his side, and pulls out a pouch of coins, which he gives to you. _Here, these are a token of the Empire's gratitude. Now, I'm a busy man. I must get on. Good luck in your future travels!_",0);
	add_dialog_str(4,"You leave the office with heads held high. Not only did you help a poor child finally find peace, you're also 350 gold pieces richer. All in a day's work...",0);
	run_dialog(1);
	end_scenario(1);
break;

beginstate 27; //Barracks message
	if(get_flag(1,11) == 0) {
		message_dialog("You enter the barracks. This single building is the combined sleeping and eating area for everyone stationed here. Despite this, it is kept in pristine condition.","At the back of the building you see another door. Perhaps you will find the Commander through there...");
		set_flag(1,11,1);
	}
break;

beginstate 28; //Hollies' Private Shelf
	message_dialog("This bookshelf is home to Commander Hollie's personal collection of literature. You notice that a lot of it is about conflict and romance - there are copies of _A Very Long Engagement_, _All Quiet on the Western Front_, and _Birdsong_.","There is nothing here to help you though, and nothing that you could learn anything from.");
break;

beginstate 29; //Hollie's shelves.
	message_dialog("These shelves contain various notes and tables concerning the running of Fort Orchid, from watch rotas to leave requests. All of it is dull, and of no use to you.","");
break;

beginstate 30; //Message divider
	if(get_flag(1,13) == 0) { //If they havent had second message
		set_state_continue(32); //show them first one
	} else {
		set_state_continue(33); //otherwise show second
	}
break;

beginstate 31;
	if(get_flag(1,12) == 0) {
		reset_dialog();
		add_dialog_str(0,"You enter this small office, and are greeted by the fort's Commanding Officer, Commander Hollie. She is tall, imposing, and severely beautiful. She is also staring straight at you.",0);
		add_dialog_str(1,"_So you're finally here. Good._ She sits down. _Right, as you know, there has been a murder. It occurred down at Fort Bluebird. A mage was found with a dagger in the back. We've drafted you in to find out who it was._",0);
		add_dialog_str(2,"_We realise that you need to scout around and such first, so I just want you to go down to Fort Bluebird, and look around. Come back to me after nosing about, and we'll see if there are any avenues you should explore further._",0);
		add_dialog_str(3,"_Oh, and there are some caves to the west. You should go there and speak to Stephens. He may have some useful information. So, you are just scouting around at the minute. Be sure to talk to the Jessica, the administrator in Fort Bluebird._",0);
		add_dialog_str(4,"She smiles slightly, an awkward and forced gesture, you think. _Good luck!_",0);
		run_dialog(1);
		set_flag(1,12,1);
		toggle_quest(2,0);
		toggle_quest(0,1);
	}
	if((get_flag(2,0) == 1) && (get_flag(1,13) == 0)) {
		reset_dialog();
		add_dialog_str(0,"You re-enter Commander Hollie's office. She is sitting at her desk busily making notes. You clear your throat to get her attention, and she immediately looks up at you.",0);
		add_dialog_str(1,"_Ah, good. You've returned. Right, tell me what you've learnt._ You begin to tell her how you spoke to Jessica, and discovered that all the mages are behaving oddly. As you continue, a soldier suddenly enters through the door.",0);
		add_dialog_str(2,"_Commander!_ he calls, _I just got a message from Magus Jessica at Fort Bluebird. She says that she has a new lead on the murder, and needs you to send the detectives, immediately! Quickly!_ His message delivered, he falls back against the wall.",0);
		add_dialog_str(3,"Hollie speaks up. _Thanks Morley. Can you go to Fort Bluebird and wait for these men?_ He nods and goes. Then Hollie says, _Right, Jessica has a lead, and it's your job to follow it. Go to Fort Bluebird, and find out what you can._",0);
		add_dialog_str(4,"_Now, go! I've sent down Captain Morley to help you. And good luck!_",0);
		run_dialog(1);
		set_flag(1,13,1);
		toggle_quest(0,0);
		toggle_quest(1,1);
		award_party_xp(200,20);
		
	}
	if((get_flag(2,5) == 1) && (get_flag(1,14) == 0)) {
		reset_dialog();
		add_dialog_str(0,"You return to Commander Hollie's office, heads held high. She looks up as you enter, and grins. _You've completed your mission, then?_",0);
		add_dialog_str(1,"You answer in the affirmative, and tell her how a trapped shade was warping the minds of the magi at Fort Bluebird to try and get them to release it. You tell her how you removed it._",0);
		add_dialog_str(3,"She listens, and finally applauds at the end. _Well done! I'm sure you'll be rewarded handsomely for this! Now, you are free to explore the fort, but not the island. We've locked the area down 'til we can combat the magic the shade left behind._",0);
		add_dialog_str(4,"_So, good work! Now, I must get on._",0);
		run_dialog(1);
		}
break;

beginstate 32;
	reset_dialog();
	add_dialog_str(0,"_Right, as you know, there has been a murder down at Fort Bluebird. A mage was found with a dagger in the back. We've drafted you in to find out who it was._",0);
	add_dialog_str(1,"_We realise that you need to scout around and such first, so I just want you to go down to Fort Bluebird, and look around. Come back to me after nosing about, and we'll see if there are any avenues you should explore further._",0);
	add_dialog_str(2,"_Oh, and there are some caves to the south-west. You may want to go there and speak to Stephens. He may have some useful information. So, to recap, you are just scouting at the minute. Be sure to talk to the Jessica, the administrator._",0);
	add_dialog_str(3,"_And one last thing. Good luck!_",0);
	run_dialog(1);
break;

beginstate 33;
	reset_dialog();
	add_dialog_str(0,"_In light of the message I just received from Captain Morley, I think it's clear what you must do. Go to Fort Bluebird, and follow Jessica's lead._",0);
	add_dialog_str(1,"_Now, go! I've sent down Captain Morley to help you. And good luck!_",0);
	run_dialog(1);
break;

beginstate 34;
	if(get_flag(1,14) == 1) {
		message_dialog("As you try to leave, you are stopped by the Fort's guards. _Nobody can leave, under orders of Commander Hollie. Sorry._","");
		block_entry(1);
	}
	if(get_flag(1,12) == 0) {
		message_dialog("You should go and see Commander Hollie before you explore the island.","");
		block_entry(1);
	}
	if(get_flag(2,5) == 1) {
		message_dialog("As you try to leave, you are stopped by the Fort's guards. _Nobody can leave, under orders of Commander Hollie. Sorry._","");
		block_entry(1);
	}
break;

beginstate 35; //Barracks lockers
	message_dialog("These lockers all have a combination lock on them. You could try and crack one of them, but in all fairness, you don't want to spend three hours trying to access somebody's dirty socks.","You leave them be.");
break;